--Nina.as
--Wicej informacji o ksztatach NINA znale mona na stronie:
--http://www.washington.edu/bibsys/mattf/nina/index.html
--myNumberOfLines wyznacza ilo linii w tworzonym ksztacie NINA.
set myNumberOfLines to 128
-- Eksperymentujc z wartociami zmiennych a_pulse i b_pulse tworzy mona rne -- ksztaty.
-- wartoci wspomnianych zmiennych nie mog by wiksze ni warto myNumberOfLines
set a_pulse to 33
set b_pulse to 37
-- zmienna myLenght kontroluje dugo linii; promie ksztatu jest mniej wicej rwny
-- dwukrotnoci tej zmiennej.
set myLength to 6
-- Aby zamkn ksztat, naley przypisa zmiennej myClosedPath warto true.
-- Jeli cieka ma pozosta otwarta, wspomnianej zmiennej naley przypisa warto   false.
set myClosedPath to true
tell application "Adobe InDesign CS2"
if (count documents) > 0 then
if (class of active window is layout window) then
set myOldXUnits to horizontal measurement units of view preferences of active document
set myOldYUnits to vertical measurement units of view preferences of active document
set horizontal measurement units of view preferences of active document to points
set vertical measurement units of view preferences of active document to points
my myDrawNina(myNumberOfLines, a_pulse, b_pulse, myLength, myClosedPath)
set horizontal measurement units of view preferences of active document to myOldXUnits
set vertical measurement units of view preferences of active document to myOldYUnits
end if
end if
end tell
on myDrawNina(myNumberOfLines, a_pulse, b_pulse, myLength, myClosedPath)
set myList to {}
repeat with myCounter from 0 to (myNumberOfLines * 2)
-- Uwaga: wyraenie "*(180/pi)" konwertuje radiany na stopnie,
-- poniewa funkcje sine/cosine wymagaj podania danych wejciowych
-- w tych wanie jednostkach.
set myAValue to ((-2 * pi * a_pulse * myCounter) / myNumberOfLines) * (180 / pi)
set myBValue to ((-2 * pi * b_pulse * myCounter) / myNumberOfLines) * (180 / pi)
set myASine to my sine_of(myAValue)
set myACosine to my cosine_of(myAValue)
set myBSine to my sine_of(myBValue)
set myBCosine to my cosine_of(myBValue)
set myX to (myACosine + myBCosine) * myLength
set myY to (myASine + myBSine) * myLength
copy {myX, myY} to end of myList
end repeat
tell application "Adobe InDesign CS2"
tell active page of active window
set myGraphicLine to make graphic line
set entire path of path 1 of myGraphicLine to myList
if myClosedPath is true then
set path type of path 1 of myGraphicLine to closed path
else
set path type of path 1 of myGraphicLine to open path
end if
end tell
end tell
end myDrawNina
-- funkcje Sine i Cosine ze zbioru Essential Subroutines Apple'a
on sine_of(x)
repeat until x is greater than or equal to 0 and x < 360
if x is greater than or equal to 360 then
set x to x - 360
end if
if x < 0 then
set x to x + 360
end if
end repeat
-- konwertujemy jednostki ze stopni na radiany
set x to x * (2 * pi) / 360
set answer to 0
set numerator to x
set denominator to 1
set factor to -(x ^ 2)
repeat with i from 3 to 40 by 2
set answer to answer + numerator / denominator
set numerator to numerator * factor
set denominator to denominator * i * (i - 1)
end repeat
return answer
end sine_of
on cosine_of(x)
repeat until x is greater than or equal to 0 and x < 360
if x is greater than or equal to 360 then
set x to x - 360
end if
if x < 0 then
set x to x + 360
end if
end repeat
-- konwertujemy jednostki ze stopni na radiany
set x to x * (2 * pi) / 360
set answer to 0
set numerator to 1
set denominator to 1
set factor to -(x ^ 2)
repeat with i from 2 to 40 by 2
set answer to answer + numerator / denominator
set numerator to numerator * factor
set denominator to denominator * i * (i - 1)
end repeat
return answer
end cosine_of